home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group95b.txt
/
000136_icon-group-sender _Thu Aug 24 09:40:09 1995.msg
< prev
next >
Wrap
Internet Message Format
|
1995-09-18
|
4KB
Received: by cheltenham.cs.arizona.edu; Thu, 24 Aug 1995 12:33:27 MST
To: icon-group@cs.arizona.edu
Date: 24 Aug 1995 09:40:09 -0700
From: yost@Yost.com (Dave Yost)
Message-Id: <41ia19$rj@Yost.com>
Organization: Dave Yost's house
Sender: icon-group-request@cs.arizona.edu
References: <41dvur$hvb@horus.infinet.com>, <qjg2irk72g.fsf@mpih16>
Subject: Editing multiple files at once
Errors-To: icon-group-errors@cs.arizona.edu
In article <qjg2irk72g.fsf@mpih16>,
Jan Peter de Ruiter <janpeter@mpi.nl> wrote:
>In article <41dvur$hvb@horus.infinet.com> btobin@infinet.com (Bruce S. Tobin) writes:
>
> I'm looking for a better way to automate (or semi-automate) some heavy
> C++ editing I'm going to have to do soon, making lots of similar changes to
> lots of different files. Is this a good use for Icon, or would I be
> better off with sed, awk, or emacs lisp? Thanks.
>
>Icon is just fine for this kind of job, but I believe you will save
>yourself a lot of trouble and time if you take a look at "gema", a
>text processing macro language that is just made for the kind of jobs
>you mention. Take a look at it: http://www.ugcs.caltech.edu/gema/.
>
>Jan
One way to do what you want is to catenate all the text files together,
edit them with whatever text editor you have handy, then burst the big
file back into its constituent files. So happens that the tool I wrote
to do this is written in Icon.
Enjoy.
Dave
======== bundle
#!/bin/sh
# Author Dave@Yost.com
usage() {
echo 1>&2 "
Usage: bundle file ...
Cats a set of text files together for editing.
Use unbundle to re-extract them.
"
exit 2
}
case $# in
0) usage
esac
for x
do
if test -f $x -a -r $x
then
echo '========' $x
cat $x
fi
done
echo '========'
======== unbundle.icn
# Author Dave@Yost.com
procedure
main (args)
local line
local pathname # a/b/c
local dirname # a/b
local filename # c
local tmpname # a/b/c-UNBUNDLE-tmp
local file
local remove
local replace
local input
local verbose
if *args ~= 1 then usage()
verbose := 1
if not (input :=
if match ("-", args[1]) then &input else open (args[1], "r")) then {
write (&errout, "Can't open ", args[1])
exit (1)
}
while line := read(input) do {
line ? {
if tab(match ("========")) then {
if \file then {
close (file)
remove := (if \verbose = 2 then
"echo 1>&2 " || pathname || " unchanged;"
else
"") ||
"rm -f " || tmpname
replace := (if \verbose = 1 then
"echo 1>&2 " || pathname || ";"
else
"") ||
"mv -f " || pathname || " " ||
backupname (pathname) ||
"; mv -f " || tmpname || " " || pathname
system ("if cmp 2>&1 > /dev/null " || tmpname || " " || pathname ||
"; then " || remove || "; else " || replace ||
"; fi")
}
if move(1) then {
pathname := tab(0)
filename := filepart (pathname)
if dirname := dirpart (pathname) then
system ("if test ! -d " || dirname ||
"; then mkdir -p " || dirname || "; fi")
tmpname := pathname || "-UNBUNDLE-tmp"
if not (file := open (tmpname, "w")) then {
write (&errout, "Can't open temp file \"", tmpname, "\"")
exit (1)
}
} else
file := &null
} else {
write (file, line)
}
}
}
if \file then close (file)
return
end
procedure
backupname (pathname)
return dirpart (pathname) || "/," || filepart (pathname) |
"," || pathname
end
procedure
dirpart (pathname)
local ind
local dirname
local filename
pathname ? {
(every ind := find ("/")) & return tab (ind)
}
end
procedure
filepart (pathname)
local ind
local dirname
local filename
pathname ? {
(every ind := find ("/")) & move (ind + 1)
filename := tab (0)
}
return filename
end
procedure
usage()
write (&errout, "\
Usage: unbundle file\
or: unbundle -\
\
Unbundles a file made with the bundle command.\
Each extracted file replaces (rather than overwrites)\
any existing file by that name unless it is unchanged.\
")
exit (2)
end
========